<?php

namespace App\Http\Middleware;

use Closure;
use App\Http\Lib\Output;
use App\Http\Lib\HttpClient;

class PrivateApi
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        $app = $request->app;
        $time = $request->ticket;
        $token = $request->token;
        $url = env('USERCENTER_URL') . '/api/private/check';
        $r = HttpClient::request('post', $url, ['app'=>$app, 'time'=>$time, 'token'=>$token]);
        if ( $r['errcode'] == 0 )
            return $next($request);
        exit(json_encode($r));
    }

}
